import React from 'react'
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom'
import { AuthProvider } from './contexts/AuthProvider'
import { MainLayout } from './components/layout/MainLayout'
import { AuthGuard } from './components/auth/AuthGuard'
import { Dashboard } from './pages/Dashboard'
import { Browse } from './pages/Browse'
import { PaperDetail } from './pages/PaperDetail'
import { Library } from './pages/Library'
import { History } from './pages/History'
import { Analytics } from './pages/Analytics'
import { Notifications } from './pages/Notifications'
import { Settings } from './pages/Settings'
import { Subscription } from './pages/Subscription'
import { Onboarding } from './pages/Onboarding'
import { Landing } from './pages/Landing'
import { AuthPages } from './pages/AuthPages'

function App() {
  return (
    <Router>
      <AuthProvider>
        <Routes>
          {/* Public routes */}
          <Route path="/" element={<Landing />} />
          <Route path="/auth/*" element={<AuthPages />} />
          
          {/* Protected routes */}
          <Route path="/app" element={
            <AuthGuard>
              <MainLayout />
            </AuthGuard>
          }>
            <Route index element={<Navigate to="/app/dashboard" replace />} />
            <Route path="dashboard" element={<Dashboard />} />
            <Route path="browse" element={<Browse />} />
            <Route path="paper/:arxivId" element={<PaperDetail />} />
            <Route path="library" element={<Library />} />
            <Route path="history" element={<History />} />
            <Route path="analytics" element={<Analytics />} />
            <Route path="notifications" element={<Notifications />} />
            <Route path="settings" element={<Settings />} />
            <Route path="subscription" element={<Subscription />} />
            <Route path="onboarding" element={<Onboarding />} />
          </Route>
          
          {/* Fallback route */}
          <Route path="*" element={<Navigate to="/" replace />} />
        </Routes>
      </AuthProvider>
    </Router>
  )
}

export default App